// Module containing the parser stream

// generic class for stream parsing
export class ParserStream<T> {

    // items to be processed
    private mItems: Array<T>;

    // position in the stream
    private mIndex: number;

    // constructor
    public constructor(items: Array<T>) {
        this.mIndex = 0;
        this.mItems = items;
    }

    // checks end of stream
    public get EOF(): boolean {
        return this.mIndex >= this.mItems.length;
    }

    // peeks one item
    public Peek(): T {
        // if EOF, return
        if (this.EOF)
            return null;
        else
            return this.mItems[this.mIndex];
    }

    // gets one item
    public Get(): T {
        // if EOF, return
        if (this.EOF)
            return null;
        var item = this.Peek();

        this.mIndex++;
        return item;
    }

    public Unget(): void {
        this.mIndex--;
    }

    // moves the index
    public MoveIndex(): void {
        if (this.EOF)
            return;
        else
            this.mIndex++;
    }
}

// Token stream
export class TokenStream extends ParserStream<string> {
}
